﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HumanResources;

namespace HRWebApp
{
    public partial class Default : System.Web.UI.Page
    {
        Company thecompany;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["company"] != null)
            {
                thecompany = (Company)Session["company"];
            }
            else
            {
                thecompany = new Company("new company", "00-0000000");
                Session["company"] = thecompany;
            }

            OutputLabel.Text = "Hello <b>TEEX</b>, it is " + DateTime.Now;
            OutputLabel2.Text = "Hello <b>TEEX</b>, it is " + DateTime.Now;

            if (!IsPostBack)
            {
                CompanyNameTb.Text = thecompany.Name;
                CompanyTaxIdTb.Text = thecompany.TaxId;
            }
            buildEmployeeList();
        }

        protected void buildEmployeeList()
        {
            EmployeesLb.Items.Clear();
            EmployeesLb.DataSource = null;
            EmployeesLb.DataSource = thecompany.AllEmployeesByName;
         //   EmployeesLb.DataTextField = "Name";
            EmployeesLb.DataBind();
        }


        protected void OnSave(object sender, EventArgs e)
        {
            try
            {
                thecompany.Name = CompanyNameTb.Text;
                thecompany.TaxId = CompanyTaxIdTb.Text;
            }
            catch (ValidationException )
            {
                OutputLabel.Text = "You entered a bad, bad value";
            }
        }

        protected void OnHire(object sender, EventArgs e)
        {
            Response.Redirect("Employee.aspx");
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            float net = thecompany.Pay();
            OutputLabel.Text = "Just paid out $" + net;
            buildEmployeeList();
        }
    }
}